package com.yiwei.ydd.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.text.Spanned;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.yiwei.ydd.R;
import com.yiwei.ydd.api.model.OilCardAgencyListModel;
import com.yiwei.ydd.util.Spans;

import butterknife.BindView;
import butterknife.ButterKnife;


/**
 * Created by xsooy-pc on 2017/10/23.
 */

public class AgencyRecordAdapter extends ItemAdapter<OilCardAgencyListModel.DatasBean, AgencyRecordAdapter.DefaultHolder> {


    private final int textSize26;


    private Context context;

    public AgencyRecordAdapter(Context context) {
        super(context);
        textSize26 = context.getResources().getDimensionPixelSize(R.dimen.x26);
        this.context = context;
    }

    @Override
    public DefaultHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new DefaultHolder(inflate(R.layout.item_agency_record, parent));
    }

    @Override
    public void onBindViewHolder(DefaultHolder holder, int position) {
        //0:待支付，1：已支付 待处理，2：已支付 处理中，3：已完成
        OilCardAgencyListModel.DatasBean item = getItem(position);
        switch (item.status) {
            case "0":
                holder.txtStatus.setText("待支付");
                holder.txtStatus.setTextColor(0xffFB5E01);
                break;
            case "1":
                holder.txtStatus.setText("待处理");
                holder.txtStatus.setTextColor(0xffFB5E01);
                break;
            case "2":
                holder.txtStatus.setText("处理中");
                holder.txtStatus.setTextColor(0xff46A62C);
                break;
            case "3":
                holder.txtStatus.setText("已完成");
                holder.txtStatus.setTextColor(0xffBBBBBB);
                break;
        }
        String address= (TextUtils.isEmpty(item.province_name)?"":item.province_name)+(TextUtils.isEmpty(item.city_name)?"":item.city_name)+(TextUtils.isEmpty(item.area_name)?"":item.area_name);

        Spanned textTwo = Spans.with(context).font("代办人手机号：" + item.mobile, textSize26, 0xff333333).
                font("\n代办人姓名："+item.username, textSize26, 0xff333333).
                font("\n收卡地址："+address, textSize26, 0xff333333).
                build();
        holder.txtInfo.setText(textTwo);
    }

    class DefaultHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.txt_status)
        TextView txtStatus;
        @BindView(R.id.txt_info)
        TextView txtInfo;

        public DefaultHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
